import {config} from "@/config";

const uniRequest = (method, url, data = {}, header = {},) => {
    const baseUrl = config.baseUrl;
    const requestUrl = baseUrl + url;
    const sessionKey = uni.getStorageSync('sessionKey');
    if (sessionKey) {
        header = {
            'sessionKey': sessionKey, ...header,
        };
    }
    return new Promise((resolve, reject) => {
        uni.request({
            method: method, url: requestUrl, data: data, header: {
                'Content-Type': 'application/multipart/form-data', ...header,
            }, success: (res) => {
                resolve(res.data);
            }, fail: (error) => {
                reject(error);
            }
        });
    });
};
export const get = (url, params = {}, header = {}, body) => {
    return uniRequest('GET', url, params, header);
};
export const post = (url, data = {}, header = {}, body) => {
    return uniRequest('POST', url, data, header);
};
